//注册审核
var regCountReminder = {
    ModuleId__: '4028803e58f1e7890158f1e7c8f2003e',
    ModelDomId__: -1,
    Count__: -1,
    load: function (force) {
        if (regCountReminder.ModelDomId__ == -1) {
            return;
        }
        var $regCountReminderCountSpan = $("#regCountReminderCountSpan_");
        if ($regCountReminderCountSpan == undefined || $regCountReminderCountSpan.length === 0) {
            $regCountReminderCountSpan =
                $("<span id='regCountReminderCountSpan_' style='color: red;'></span>").appendTo(
                    $("#"
                      + regCountReminder.ModelDomId__
                      + "_span"));
        }
        if (force == true || regCountReminder.Count__ == -1) {
            $.ajax({
                       url: "index-countNewReg",
                       dataType: "json",
                       success: function (data) {
                           var num = data.data;
                           if (num == "" || num == 0) {
                               regCountReminder.Count__ = 0;
                           } else {
                               regCountReminder.Count__ = num;
                           }
                           regCountReminder.load(false);
                       }
                   });
        }
        if (regCountReminder.Count__ != -1) {
            $regCountReminderCountSpan.text("（" + regCountReminder.Count__ + "）");
        }
    }
}

//收发货人审核
var bgDataCountReminder = {
    ModuleId__: 'f0fc943258f1574c0158f237d39300c0',
    ModelDomId__: -1,
    Count__: -1,
    load: function (force) {
        if (bgDataCountReminder.ModelDomId__ == -1) {
            return;
        }
        var $bgDataCountReminderCountSpan = $("#bgDataCountReminderCountSpan_");
        if ($bgDataCountReminderCountSpan == undefined || $bgDataCountReminderCountSpan.length
                                                          === 0) {
            $bgDataCountReminderCountSpan =
                $("<span id='bgDataCountReminderCountSpan_' style='color: red;'></span>").appendTo(
                    $("#"
                      + bgDataCountReminder.ModelDomId__
                      + "_span"));
        }
        if (force == true || bgDataCountReminder.Count__ == -1) {
            $.ajax({
                       url: "index-countCompanyQpTemp",
                       dataType: "json",
                       success: function (data) {
                           var num = data.data;
                           if (num == "" || num == 0) {
                               bgDataCountReminder.Count__ = 0;
                           } else {
                               bgDataCountReminder.Count__ = num;
                           }
                           bgDataCountReminder.load(false);
                       }
                   });
        }
        if (bgDataCountReminder.Count__ != -1) {
            $bgDataCountReminderCountSpan.text("（" + bgDataCountReminder.Count__ + "）");
        }
    }
}

//付款审核
var offlinePayCountReminder = {
    ModuleId__: '4028803e58f1e7890158f1e7bc770004',
    ModelDomId__: -1,
    Count__: -1,
    load: function (force) {
        if (offlinePayCountReminder.ModelDomId__ == -1) {
            return;
        }
        var $offlinePayCountReminderCountSpan = $("#offlinePayCountReminderCountSpan_");
        if ($offlinePayCountReminderCountSpan == undefined
            || $offlinePayCountReminderCountSpan.length
               === 0) {
            $offlinePayCountReminderCountSpan =
                $("<span id='offlinePayCountReminderCountSpan_' style='color: red;'></span>")
                    .appendTo(
                        $("#"
                          + offlinePayCountReminder.ModelDomId__
                          + "_span"));
        }
        if (force == true || offlinePayCountReminder.Count__ == -1) {
            $.ajax({
                       url: "index-countOfflinePay",
                       dataType: "json",
                       success: function (data) {
                           var num = data.data;
                           if (num == "" || num == 0) {
                               offlinePayCountReminder.Count__ = 0;
                           } else {
                               offlinePayCountReminder.Count__ = num;
                           }
                           offlinePayCountReminder.load(false);
                       }
                   });
        }
        if (offlinePayCountReminder.Count__ != -1) {
            $offlinePayCountReminderCountSpan.text("（" + offlinePayCountReminder.Count__ + "）");
        }
    }
}

//已受理模块显示申请驳回数量
var applyRejectCount = {
    ModuleId__: '4028803e58f1eded0158f1ee1d440002',//已受理模块
    ModelDomId__: -1,
    Count__: -1,
    load: function (force) {
        if (applyRejectCount.ModelDomId__ == -1) {
            return;
        }
        var $applyRejectCountSpan = $("#applyRejectCountSpan_");
        if ($applyRejectCountSpan == undefined
            || $applyRejectCountSpan.length
               === 0) {
            $applyRejectCountSpan =
                $("<span id='applyRejectCountSpan_' style='color: red;'></span>").appendTo(
                    $("#"
                      + applyRejectCount.ModelDomId__
                      + "_span"));
        }
        if (force == true || applyRejectCount.Count__ == -1) {
            $.ajax({
                       url: "index-applyRejectCount",
                       dataType: "json",
                       success: function (data) {
                           var num = data.data;
                           if (num == "" || num == 0) {
                               applyRejectCount.Count__ = 0;
                           } else {
                               applyRejectCount.Count__ = num;
                           }
                           applyRejectCount.load(false);
                       }
                   });
        }
        if (applyRejectCount.Count__ != -1) {
            $applyRejectCountSpan.text("（" + applyRejectCount.Count__ + "）");
        }
    }
}

//驳回模块id
/*var rejectModelId__="402880bd510df68201510df881850000";*/
var rejectModelId__ = "4028803e58f1eded0158f1ee2204000f";
//是否更新驳回模块的数据
var rejectModelDomId__ = -1;
//缓存被驳回单证的数量
var rejectCount__ = -1;
//更新页面菜单中的驳回数量数据
/**
 * 只有在fouce参数为true和页面上没有缓存驳回数据时才会去后台查询被驳回单证的数量
 * @param fouce 是否强制刷新，true为强制刷新
 */
var loadRejectCount = function (fouce) {
    if (rejectModelDomId__ == -1) {
        return;
    }
    var $rejectCountSpan = $("#rejectCount_");
    if ($rejectCountSpan == undefined || $rejectCountSpan.length === 0) {
        $rejectCountSpan =
            $("<span id='rejectCount_' style='color: red;'></span>").appendTo(
                $("#" + rejectModelDomId__
                  + "_span"));
    }
    if (fouce == true || rejectCount__ == -1) {
        $.ajax({
                   url: "index-countReject",
                   dataType: "json",
                   success: function (data) {
                       var num = data.data;
                       if (num == "" || num == 0) {
                           rejectCount__ = 0;
                       } else {
                           rejectCount__ = num;
                       }
                       loadRejectCount(false);
                   }
               });
    }
    if (rejectCount__ != -1) {
        $rejectCountSpan.text("（" + rejectCount__ + "）");
    }
};
var obj;
var tabObj;
var silent = false;
var headHeight = 108;
var mainHeight = document.documentElement.clientHeight - headHeight - 5;
var openIndex = 1;
var setting = {
    async: {
        enable: true,
        url: "index-module.do",
        autoParam: ["id"]//,
        // dataFilter: filter
    },
    data: {
        key: {},
        simpleData: {
            pIdKey: "parent.id"
        }
    },
    callback: {
        onClick: function (event, treeId, treeNode, clickFlag) {
            if (treeNode.isParent == true || treeNode.isParent == "true") {
                if (treeNode.level == 0) {
                    var nodes = obj.getNodesByParam("open", true);
                    $.each(nodes, function (i, n) {
                        if (n.parent == null) {
                            obj.expandNode(n, false);
                        }
                    });
                    obj.expandNode(treeNode, true);
                } else {
                    obj.expandNode(treeNode, !treeNode.open);
                }
            } else {
                var nid = treeNode.id;
                try {
                    tabObj.getTitle(nid);
                    tabObj.refresh(nid);
                    tabObj.show(nid, null);

                } catch (e) {
                    tabObj.addTab({
                                      id: nid,
                                      title: treeNode.name,
                                      html: "<iframe id='" + nid + "Frame' src='"
                                            + treeNode.link
                                            + "' width='100%' height='100%' frameborder='0'></iframe>",
                                      closable: true,
                                      disabled: false
                                  });
                    createCloseMenu(nid);
                }
            }
            //点击菜单时更新被驳回单证的数量
            loadRejectCount();
        },
        onNodeCreated: function (event, treeId, treeNode) {
            if (treeNode.isParent && treeNode.level < 1) {
                obj.reAsyncChildNodes(treeNode, "refresh", silent);
                if (!silent) {
                    silent = true;
                }
            }
            //驳回节点被创建时，更新被驳回的单数量
            if (treeNode.id === rejectModelId__) {
                rejectModelDomId__ = treeNode.tId;
                loadRejectCount();
            }
            if (treeNode.id === regCountReminder.ModuleId__) {
                regCountReminder.ModelDomId__ = treeNode.tId;
                regCountReminder.load();
            }
            if (treeNode.id === bgDataCountReminder.ModuleId__) {
                bgDataCountReminder.ModelDomId__ = treeNode.tId;
                bgDataCountReminder.load();
            }
            if (treeNode.id === offlinePayCountReminder.ModuleId__) {
                offlinePayCountReminder.ModelDomId__ = treeNode.tId;
                offlinePayCountReminder.load();
            }
            //更新申请驳回等待处理的报关单数量
            if (treeNode.id === applyRejectCount.ModuleId__) {
                applyRejectCount.ModelDomId__ = treeNode.tId;
                applyRejectCount.load();
            }
        },
        onAsyncSuccess: function (event, treeId, treeNode, msg) {
            if (treeNode == null) {
                //resetTreeHeight();
            }
        }
    }
};
function filter(treeId, parentNode, childNodes) {
    if (!childNodes) {
        return null;
    }
    return childNodes.modules;
}
$(document)
    .ready(
        function () {
            tabObj = new TabPanel(
                {
                    renderTo: 'main',
                    width: '100%',
                    height: mainHeight + 'px',
                    active: 0,
                    items: [{
                        id: 'welcome',
                        title: '首页',
//									align:'center',
//									html : '<iframe src="business/business-businessList.do"
// width="100%" height="100%" frameborder="0"></iframe>',
                        html: '<iframe src="customWelcome" width="100%" height="100%" frameborder="0"></iframe>',
                        closable: false
                    }]
                });
            obj = $.fn.zTree.init($("#module"), setting);
            createCloseMenu("welcome", true);
            $(window).resize(function () {
                resetWH(tabObj);
            });
        });
function getAllTab() {
    var tabsHtml = $("#main .tabpanel_mover li");
    var tabIds = new Array();
    $.each(tabsHtml, function (i, n) {
        if (n.id != "welcome") {
            tabIds.push(n.id);
        }
    });
    return tabIds;
}
function loginOut() {
    Cookies("readIds", "");
    location.href = "logout";
}
/**
 * 重新设置树的高度
 *
 * @param height
 */
function resetTreeHeight(height) {
    if (height == undefined) {
        height = document.documentElement.clientHeight - headHeight - 5;
    }
    var o = obj.getNodes();
    var count = 0;
    if (o && o.length != 0) {
        count = o.length;
    }
    height = height - 35 * count;
    document.styleSheets[document.styleSheets.length - 1].rules[0].style.height = height
                                                                                  + 'px';
}
/**
 * 获取滚动条宽度
 *
 * @returns {Number}
 */
function getScrollWidth() {
    var noScroll, scroll, oDiv = document.createElement("DIV");
    oDiv.style.cssText =
        "position:absolute; top:-1000px; width:100px; height:100px; overflow:hidden;";
    noScroll = document.body.appendChild(oDiv).clientWidth;
    oDiv.style.overflowY = "scroll";
    scroll = oDiv.clientWidth;
    document.body.removeChild(oDiv);
    return noScroll - scroll;
}
/**
 * 重新设置页面的高宽
 */
function resetWH(tabObj) {
    var screenWidth = document.documentElement.clientWidth;
    var treeWidth = 195;
    if ($("#frmTitle").css("display") == "none") {
        treeWidth = 0;
    }
    var barWidth = 16;
    var screenHeight = document.documentElement.clientHeight;
    var topHeight = 108;
    var haveXScroll = screenWidth < (document.documentElement.offsetWidth - 4);
    var haveYScroll = screenHeight < (document.documentElement.offsetHeight - 4);
    var scroll = haveXScroll || haveYScroll ? getScrollWidth() : 0;
    var height = screenHeight - topHeight - 3 + scroll;
    var width = screenWidth - treeWidth - barWidth - 8 + scroll;
    //resetTreeHeight(height);
    $.tabResize(tabObj, {
        "width": width,
        "height": height
    });
}

/**
 * 生成右键菜单
 *
 * @param controlId
 * @param isAll
 */
function createCloseMenu(controlId, isAll) {
    var all = false;
    if (isAll) {
        all = true;
    }
    var allCloseMenu = "allMenu3513";
    if ($("#" + allCloseMenu).length == 0) {
        var d = "<div class='contextMenu' id='"
                + allCloseMenu
                + "' style='display:none;'><ul><li id='closeCurrent'>关闭</li><li id='closeOther'>关闭其他</li><li id='closeAll'>关闭所有</li></ul></div>";
        $("body").append(d);
    }

    $("#" + controlId).contextMenu(allCloseMenu, {
        onContextMenu: function (e) {
            return true;
        },
        onShowMenu: function (e, menu) {
            if (all) {
                $('#closeCurrent', menu).remove();
            }
            return menu;
        },
        bindings: {
            'closeCurrent': function (t) {
                tabObj.kill(t.id);
            },
            'closeOther': function (t) {
                var tabIds = getAllTab();
                $.each(tabIds, function (i, n) {
                    if (t.id != n) {
                        tabObj.kill(n);
                    }
                });
                if (t.id != "welcome") {
                    $("#" + t.id).addClass("active");
                    $("#welcome").removeClass("active");
                }
            },
            'closeAll': function (t) {
                var tabIds = getAllTab();
                $.each(tabIds, function (i, n) {
                    tabObj.kill(n);
                });
            }
        },
        itemStyle: {
            listStyleType: 'none',
            fontFamily: '宋体',
            fontSize: '12px',
            color: '#000',
            textIndent: '1em'
        }
    });
}
/* 控制左侧栏收缩 */
function switchSysBar() {
    if (switchPoint.innerText == 3) {
        switchPoint.innerText = 4;
        document.all("frmTitle").style.display = "none";
    } else {
        switchPoint.innerText = 3;
        document.all("frmTitle").style.display = "";
    }
    resetWH(tabObj);
}

function linkTO(parm) {
    if (parm == "order") {
        tabObj.addTab({
                          id: "order",
                          title: "首页-在线下单",
                          html: "<iframe id='orderFrame' src='business/business-main.do' width='100%' height='100%'frameborder='0'></iframe>",
                          closable: true,
                          disabled: false
                      });
        //window.location.href = "business/business-main.do";
    } else if (parm == "trailList") {
        tabObj.addTab({
                          id: "trailList",
                          title: "首页-拖车业务管理",
                          html: "<iframe id='trailListFrame' src='business/trail-main.do' width='100%' height='100%'frameborder='0'></iframe>",
                          closable: true,
                          disabled: false
                      });
        //window.location.href = "business/trail-main.do";
    } else if (parm == "wxhbhd") {
        tabObj.addTab({
                          id: "wxhbhd",
                          title: "首页-微信红包活动",
                          html: "<iframe id='wxhbhdFrame' src='weixinhuodong.html' width='100%' height='100%'frameborder='0'></iframe>",
                          closable: true,
                          disabled: false
                      });
        //window.location.href = "business/trail-main.do";
    } else if (parm == "operation") {
        //window.location.href = "";
    } else if (parm == "helpCenter") {
        tabObj.addTab({
                          id: "helpCenter",
                          title: "首页-帮助中心",
                          html: "<iframe id='helpCenterFrame' src='regLogin.do' width='100%' height='100%'frameborder='0'></iframe>",
                          closable: true,
                          disabled: false
                      });
        //window.location.href = "regLogin.do";
    } else if (parm == "service") {
        tabObj.addTab({
                          id: "service",
                          title: "首页-服务协议",
                          html: "<iframe id='serviceFrame' src='serviceAgreement.do' width='100%' height='100%'frameborder='0'></iframe>",
                          closable: true,
                          disabled: false
                      });
        //window.location.href = "serviceAgreement.do";
    }
}

//未审核单证提示功能 star
window.onload = function () {//加载
    //悬浮框
//	var b = new scrollBanner(10, 15);
//    b.add(document.getElementById("rwc"),   80,   10,   1,
// document.getElementById("rwc_c"),"fixed");
    //悬浮框
    document.getElementById('winpop').style.height = '0px';
    setInterval("refresh()", 10000);
}

function refresh() {
    $.ajax({
               url: "index-refresh.do",
               dataType: "json",
               success: function (data) {
                   if (!data) {
                       return;
                   }
                   var msg = data.msg ? $.parseJSON(data.msg) : "";
                   if (msg !== undefined && msg != "" && msg.state == 0) {
// 				tips_pop();
// 				$("#message").text($.parseJSON(data.msg).msg);
                       var count = msg.msg;
                       $.ajax({
                                  url: "index-companyType.do",
                                  dateType: "json",
                                  success: function (data) {
                                      if ($.parseJSON(data.msg).type == "CC") {
                                          $("#message").text(count);
                                          tips_pop();
                                      }
                                  }
                              });
                   }
               }
           });
}

function tips_pop() {
    var MsgPop = document.getElementById("winpop");
    var popH = parseInt(MsgPop.style.height);//将对象的高度转化为数字
    if (popH == 0) {
        MsgPop.style.display = "block";//显示隐藏的窗口
        show = setInterval("changeH('up')", 2);
    } else {
        hide = setInterval("changeH('down')", 2);
    }
}

function changeH(str) {
    var MsgPop = document.getElementById("winpop");
    var popH = parseInt(MsgPop.style.height);
    if (str == "up") {
        if (popH <= 100) {
            MsgPop.style.height = (popH + 4).toString() + "px";
        } else {
            clearInterval(show);
        }
    }
    if (str == "down") {
        if (popH >= 4) {
            MsgPop.style.height = (popH - 4).toString() + "px";
        } else {
            clearInterval(hide);
            MsgPop.style.display = "none"; //隐藏DIV
        }
    }
}

function linkTo() {
    tabObj.addTab({
                      id: "pendingAuditList",
                      title: "已提交待审核",
                      html: "<iframe id='orderFrame' src='business/declaration-listForSupToValidate.do?declaraState=DS01' width='100%' height='100%'frameborder='0'></iframe>",
                      closable: true,
                      disabled: false
                  });
}
//未审核单证提示功能 end






